import DataModel from 'framework/datamodel';
import Api from '@/util/api'

export default class GeneralFormReqeust {
  _config = {
    method: 'post',
    action: null
  };

  constructor(config = null) {
    if (config !== null) {
      this._config = config;
    }
  }

  async submit(formData) {
    const response = await Reflect.get(Api, this._config.method)(this._config.action, formData);
    let model = DataModel.buildModel(response.data.type, response.data);
    return model;
  }

  action(action = null) {
    if (action !== null) {
      this._config.action = action;
    }
    return this._config.action;
  }

  method(method = null) {
    if (method !== null) {
      this._config.method = method;
    }
    return this._config.method;
  }

}
